#include "point.h"
#include "geometry.h"
#include "adaptive.h"
#include "interval.h"

int complete_turn(const point& a, const point& b, const point& c)
{
   int abc = eps_turn(a, b, c);
   if (abc != 0)
      return abc;

   abc = interval_turn(a, b, c);
   if (abc != 0)
      return abc;

   return adaptive_turn(a, b, c);      
}


bool intersection(const point& a, const point& b, const point& c, const point& d)
{
   if (bounding_box_check(a, b, c, d))
      return false;

   if ((complete_turn(a, b, c) * complete_turn(a, b, d) <= 0) && (complete_turn(c, d, a) * complete_turn(c, d, b) <= 0))
      return true;

   return false;
}

bool intersection(const point* points)
{
   return intersection(points[0], points[1], points[2], points[3]);
}